﻿using System.Collections.ObjectModel;
using 高级控件演示.Domain;

namespace 高级控件演示.ViewModels
{
    public class MainViewModel : BindableBase
    {
        public ObservableCollection<MenuCategory> MenuCategories { get; set; }
        public DelegateCommand<object> ItemClickCommand { get; private set; }

        private readonly IRegionManager regionManager;

        public MainViewModel(IRegionManager regionManager)
        {
            this.regionManager = regionManager;

            var rootNode = new MenuCategory("编程内功", "PineTree", "");

            var childNode1 = new MenuCategory("高级控件使用", "Folder","",
                    new MenuCategory("ItemsControl", "TextBox", "ItemsControlDemo"),
                    new MenuCategory("语音播放", "TextBox", "SpeekContent"),
                    new MenuCategory("打印文字", "TextBox", "PrintContent"));
            childNode1.Parent = rootNode;

            var childNode2 = new MenuCategory("设计模式", "Folder","",
                    new MenuCategory("单例", "TextBox", ""),
                    new MenuCategory("观察者", "TextBox", "")
                );
            childNode2.Parent = rootNode;
            rootNode.MenuItems = new ObservableCollection<Domain.MenuCategory>()
            {
                childNode1,childNode2
            };



            MenuCategories = new ObservableCollection<MenuCategory>
            {
                rootNode
            };


            ItemClickCommand = new DelegateCommand<object>(ItemClickFunc);

        }

        /// <summary>
        /// 菜单单击事件
        /// </summary>
        /// <param name="parameter"></param>
        private void ItemClickFunc(object parameter)
        {
            MenuCategory menuItem = parameter as MenuCategory;
            string navPath = menuItem.NavigationPath;
            if (!string.IsNullOrEmpty(navPath))
            {
                regionManager.RequestNavigate("ContentRegion", navPath);
            }
        }
    }
}
